var nbmlsidemenu=document.querySelectorAll(".nb-mlside-menu");
var bxslider=document.querySelector(".bxslider");
var clearT;
var clearT1;
var index=0;
var lt=document.querySelector(".left-controls");
var rt=document.querySelector(".right-controls");
var circle=document.querySelectorAll(".bx-pager-link");
var pro=document.querySelectorAll(".product");
var lis=document.querySelectorAll(".list");
var is_run=true;
var h=0;
var xzbs=$(".xzbs li");


//判断列表里面商品是否大于6个
for(var i=0;i<nbmlsidemenu.length;i++){
	if(nbmlsidemenu[i].childElementCount>6){
		var t=0;
		nbmlsidemenu[i].style.width="400px";
		for(var j=6;j<nbmlsidemenu[i].childElementCount;j++){
			nbmlsidemenu[i].children[j].setAttribute("style","position:absolute;top:"+t+"px;left:200px;");
			t+=89;
		}
	}
}

//自动轮播
setInterval(function(){
	if(is_run){
		if(index==0){//当下标为第一个时清除，上一个的z-index
			bxslider.children[bxslider.childElementCount-1].setAttribute("style","z-index: 0;opacity: 0;");
		}else{
			bxslider.children[index-1].setAttribute("style","z-index: 0;opacity: 0;");
		}
		bxslider.children[index].setAttribute("style","z-index: 50;opacity: 1;");
		lunbo(index);
		index++;
		if(index==bxslider.childElementCount){
			index=0;
		}
	}
	is_run=true;
},4500)
//轮播圆点
function lunbo(index){
	for(var i=0;i<bxslider.childElementCount;i++){
		circle[i].classList.remove("active");
	}
	circle[index].classList.add("active");
}
//轮播圆点点击
for(let i=0;i<circle.length;i++){
	circle[i].addEventListener("click",function(){
		bxslider.children[index].setAttribute("style","z-index: 0;opacity: 0;");
		bxslider.children[i].setAttribute("style","z-index:50;opacity: 1;");
		lunbo(i);
		index=i;
		is_run=false;
	})
}
//左移动
lt.addEventListener("click",function(){
	is_run=false;
	if(index==0){
		bxslider.children[bxslider.childElementCount-1].setAttribute("style","z-index: 50;opacity: 1;");
		bxslider.children[index].setAttribute("style","z-index: 0;opacity: 0;");
		index=bxslider.childElementCount-1;
		lunbo(index);
	}else{
		bxslider.children[index].setAttribute("style","z-index: 0;opacity: 0;");
		bxslider.children[index-1].setAttribute("style","z-index: 50;opacity: 1;");
		lunbo(index-1);
		index--;
	}
})
//右移动
rt.addEventListener("click",function(){
	is_run=false;
	if(index==bxslider.childElementCount-1){
		index=0;
		bxslider.children[index].setAttribute("style","z-index: 50;opacity: 1;");
		bxslider.children[bxslider.childElementCount-1].setAttribute("style","z-index: 0;opacity: 0;");
		lunbo(index);
	}else{
		bxslider.children[index].setAttribute("style","z-index: 0;opacity: 0;");
		bxslider.children[index+1].setAttribute("style","z-index: 50;opacity: 1;");
		lunbo(index+1);
		index++;
		if(index==bxslider.childElementCount){
			index=0;
		}
	}
})

xzbs.on("mouseover",function(){
	$(this).addClass("bgc").siblings().removeClass("bgc");
});